package com.yangxk.kadmin.web.module.system.controller;

import com.yangxk.kadmin.common.beans.Result;
import com.yangxk.kadmin.web.module.system.form.AuthForm;
import com.yangxk.kadmin.web.module.system.form.AuthQueryForm;
import com.yangxk.kadmin.web.module.system.po.Auth;
import com.yangxk.kadmin.web.module.system.service.AuthService;
import com.yangxk.kadmin.web.module.system.vo.AuthTree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    private AuthService authService;

    @GetMapping("/tree")
    public Result<List<AuthTree>> findAuthTree() {
        return Result.ofSuccess(authService.queryAuthTree());
    }

    @GetMapping("/list")
    public Result<List<Auth>> queryByParent(AuthQueryForm form) {
        return Result.ofSuccess(authService.queryByParent(form));
    }

    @PostMapping("/add")
    public Result<Long> add(@RequestBody AuthForm authForm) {
        return Result.ofSuccess(authService.addAuth(authForm));
    }

    @PostMapping("/update")
    public Result update(@RequestBody AuthForm authForm) {
        authService.updateAuth(authForm);
        return Result.ofSuccess();
    }

    @GetMapping("/delete")
    public Result delete(long id) {
        authService.deleteAuth(id);
        return Result.ofSuccess();
    }

    @GetMapping("/deleteBatch")
    public Result delete(String ids) {
        authService.deleteAuth(ids);
        return Result.ofSuccess();
    }

    @GetMapping("/info")
    public Result<Auth> findById(long id) {
        return Result.ofSuccess(authService.selectByPrimaryKey(id));
    }
}
